package yunwo.cn.yzstation.other;

import android.app.Activity;
import android.view.Display;
import android.view.Gravity;
import android.view.Window;
import android.view.WindowManager;

import yunwo.cn.yzstation.R;
import yunwo.cn.yzstation.utils.DensityUtil;


public class ShowAnimationDialogUtil {

    /**
     * 显示从下至上弹出对话框
     *
     * @param activity
     * @param resId    自定义dialog资源文件id
     * @return
     */
    public static PickDialog showDialog(Activity activity, int resId) {
        PickDialog dialog = new PickDialog(activity, R.style.CityPickDialog,
                resId);
        Window window = dialog.getWindow();
        window.setGravity(Gravity.BOTTOM); // 此处可以设置dialog显示的位置
        window.setWindowAnimations(R.style.CityPickDialogAnimation); // 添加动画
        dialog.show();
        WindowManager windowManager = activity.getWindowManager();
        Display display = windowManager.getDefaultDisplay();
        WindowManager.LayoutParams lp = dialog.getWindow().getAttributes();
        lp.width = (int) (display.getWidth()); // 设置宽度
        dialog.getWindow().setAttributes(lp);
        return dialog;
    }
    /**
     * 显示从下至上弹出对话框
     *
     * @param activity
     * @param resId    自定义dialog资源文件id
     * @return
     */
    public static PickDialog showDialog(Activity activity, int resId, int gravity, boolean isHalfScreen, boolean cancel) {
        PickDialog dialog = new PickDialog(activity, R.style.CityPickDialog,
                resId);
        Window window = dialog.getWindow();
        window.setGravity(gravity); // 此处可以设置dialog显示的位置
        window.setWindowAnimations(R.style.HalfScreenDialogAnimation); // 添加动画
        dialog.show();
        WindowManager windowManager = activity.getWindowManager();
        Display display = windowManager.getDefaultDisplay();
        WindowManager.LayoutParams lp = dialog.getWindow().getAttributes();
        if(isHalfScreen){
            lp.width = (int) (display.getWidth()/1.5); // 设置宽度
//            lp.height = display.getHeight();
        }else if(cancel){
            lp.width = (int) (display.getWidth()/2); // 设置宽度
            lp.height = display.getHeight();
        }
        else {
            lp.width = (int) (display.getWidth()/1.5); // 设置宽度
        }
        dialog.setCanceledOnTouchOutside(true);
        dialog.getWindow().setAttributes(lp);
        return dialog;
    }
    /**
     *
     * @param activity
     * @param resId
     * @param
     *            ，单位为dp
     * @return
     */
    public static PickDialog showDialog(Activity activity, int resId, int height, int gravity) {
        PickDialog dialog = new PickDialog(activity, R.style.CityPickDialog,
                resId);
        Window window = dialog.getWindow();
        window.setGravity(gravity); // 此处可以设置dialog显示的位置
        window.setWindowAnimations(R.style.CityPickDialogAnimation); // 添加动画
        dialog.show();

        WindowManager windowManager = activity.getWindowManager();
        Display display = windowManager.getDefaultDisplay();
        WindowManager.LayoutParams lp = dialog.getWindow().getAttributes();
        lp.width = (int) (display.getWidth()); // 设置宽度
        lp.height = DensityUtil.dip2px(activity, height);
        dialog.getWindow().setAttributes(lp);
        return dialog;
    }

}
